<template>
  <a-modal
    title="住宿变更记录"
    :width="900"
    :visible="visible"
    @cancel="handleCancel"
    cancelText="关闭"
    :maskClosable="false"
    :footer="null"
  >
    <a-spin :spinning="confirmLoading">
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
      >
      </a-table>
    </a-spin>
  </a-modal>
</template>

<script>
  import { getAction } from '@/api/manage'
  import moment from 'moment'

  export default {
    name: 'DormitoryStudentChangeLogModal',
    data () {
      return {
        visible: false,
        confirmLoading: false,
        loading: false,
        studentId: '',
        // 表头
        columns: [
          {
            title: '变更类型',
            align: "center",
            dataIndex: 'changeType'
          },
          {
            title: '原宿舍',
            align: "center",
            dataIndex: 'oldRoomId',
            customRender: (text) => {
              return text || '-';
            }
          },
          {
            title: '原床位',
            align: "center",
            dataIndex: 'oldBedNo',
            customRender: (text) => {
              return text || '-';
            }
          },
          {
            title: '新宿舍',
            align: "center",
            dataIndex: 'newRoomId',
            customRender: (text) => {
              return text || '-';
            }
          },
          {
            title: '新床位',
            align: "center",
            dataIndex: 'newBedNo',
            customRender: (text) => {
              return text || '-';
            }
          },
          {
            title: '变更原因',
            align: "center",
            dataIndex: 'changeReason',
            customRender: (text) => {
              return text || '-';
            }
          },
          {
            title: '操作人',
            align: "center",
            dataIndex: 'operator'
          },
          {
            title: '变更时间',
            align: "center",
            dataIndex: 'changeTime',
            customRender: (text) => {
              return text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '';
            }
          }
        ],
        dataSource: [],
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条";
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        url: {
          list: '/dormitory/student/changeLogs',
        }
      }
    },
    created () {
    },
    methods: {
      // 显示弹窗
      show (studentId) {
        this.studentId = studentId;
        this.visible = true;
        this.loadData();
      },
      // 加载数据
      loadData () {
        this.loading = true;
        getAction(this.url.list, { studentId: this.studentId }).then((res) => {
          if (res.success) {
            this.dataSource = res.result;
            this.ipagination.total = res.result.length;
          }
          this.loading = false;
        });
      },
      // 关闭
      handleCancel () {
        this.close();
      },
      close () {
        this.visible = false;
      }
    }
  }
</script> 